package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 
    
     /* Impliments the dvd control in to the dvdUI */
    public DvdUI(DVDCtr dvdCtr)
    {
        this.dvdCtr = dvdCtr;        
    }
     /* Starst the DVDUI */
    public void start()
    {
        dvdMenu();
    }
     /* Here you can chose to find , create, delete a dvd, list all dvds and to create and to list all copies of the dvds  */
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit) {   
            //show menu and return the user's choise
            int choice =   writeDVDMenu();
            if (choice == 1) {            
                findDVD();
            }
            else {
                if(choice == 2) {
                   createDVD();
                }
                else {
                    if(choice == 3) {
                        createCopy();
                    }
                    else {
                        if(choice == 4) {
                             deleteDVD();
                        }
                        else {
                            if(choice == 5) {
                                listAllDvds();
                            }
                            else {
                                if(choice == 6) {
                                    listAllCopies();
                                }
                                else {
                                exit = true;
                                }
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else           
        }//end while
    }
     /* Prints out all the choices you can make */
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD description");
            System.out.println(" (3) Create DVD specimen");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Show DVD copies");
            System.out.println(" (7) Return");
            System.out.print("\n Make your choice: ");         
            int choice = keyboard.nextInt();
            return choice;
    }
     /* Readst the input for the DVD number */
    private long inputDVDNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD number: ");
        long no = keyboard.nextInt();
        return no;
    }
         /* Reads the title that the user inputs */
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
     /* Reads the copy number */
    private int inputCopyNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the copy number: ");
        int no = keyboard.nextInt();
        return no;
    }
     /* Reads the publication date that the user has inputed */
    private String inputDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD publication date: " );
        String publicationDate = keyboard.nextLine();
        return publicationDate;
    }
     /* Reads the artis of the DVD */
    private String inputArtist()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD artist: " );
        String artist = keyboard.nextLine();
        return artist;
    }
     /* Reads the serial number of the DVD */
     private int inputSerialNumber()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD Serial No: " );
        int serialNumber = keyboard.nextInt();
        return serialNumber;
    }
     /* Reads the purchase date that the user has inputed */
     private int inputPurchaseDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD purchase date: " );
        int purchaseDate = keyboard.nextInt();
        return purchaseDate;
    }
     /* Reads the purchase price that the user has inputed */
     private int inputPurchasePrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD purchase price: " );
        int purchasePrice = keyboard.nextInt();
        return purchasePrice;
    }
    
    //there is need for more methods to read information about DVDs
    //and methods to display the information
   /* Finds a spesific dvd */
    private void findDVD()
    {     
        long id = inputDVDNo();
        dvdCtr.findDVD(id);
        Scanner keyboard = new Scanner(System.in); 
        keyboard.nextLine();
    }
     /* Creates a DVD */
    private void createDVD()
    {
        long id = inputDVDNo();
        String title = inputTitle();
        String artist = inputArtist();
        String publicationDate = inputDate();
        dvdCtr.createDVD(id, title, artist, publicationDate);
    }
     /* Makes a copy of a DVD */
    private void createCopy()
    {
        long id = inputDVDNo();
        int SerialNumber = inputSerialNumber();
        int PurchaseDate = inputPurchaseDate();
        int PurchasePrice = inputPurchasePrice();  
        dvdCtr.createCopy(id, SerialNumber, PurchaseDate, PurchasePrice);
    }
     /* Deletes a DVD */
    private void deleteDVD()
    {
        long id = inputDVDNo();
        dvdCtr.deleteDVD(id);
    }
     /* List all DVDs */
    private void listAllDvds()
    {
       dvdCtr.listAllDvds();
       Scanner keyboard = new Scanner(System.in); 
       keyboard.nextLine();
    }
     /* List's all copies of the DVD */
    private void listAllCopies()
    {
        dvdCtr.listCopies(inputDVDNo());
        Scanner keyboard = new Scanner(System.in); 
       keyboard.nextLine();
    }     
    
}